package com.wn.naturalbiorhythms;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;

import com.wn.naturalbiorhythms.bean.NaturalBirthdayAdapter;
import com.wn.naturalbiorhythms.tool.BirthdaySettingsSharePref;
import com.wn.naturalbiorhythms.tool.NaturalBiorhythmsAlgorithm;

public class DoubleTowPersonActivity extends Activity {

	private BirthdaySettingsSharePref bsspref;
	private ListView listView;
	private NaturalBirthdayAdapter adpter;
	private DTPersonHandler handler;
	
	private RadioButton radioButton1_cycle;
	private RadioButton radioButton2_critical;
	private RadioButton radioButton3_climax;
	
	private RadioButton radioButton4_lowtide;
	private RadioButton radioButton5_climax_h;
	private RadioButton radioButton6_lowtide_l;
	
	private RadioGroup rg_timeLen;
	private RadioGroup rg_types_tab;
	
	private int dayType_checkSwitch = DTPersonHandler.DAY_TYPE_1_CYCLE;
	private int tabCurrent_checkSwitch = 0;
	
		
	private long birthday1;
	private byte sex1;
	private byte sex2;
	private long birthday2;
	private NaturalBiorhythmsAlgorithm nba1;
	private NaturalBiorhythmsAlgorithm nba2;
	//private List<String>data = new ArrayList<String>();
	List<Map<String, Object>> data = new ArrayList<Map<String,Object>>();
	
	
	private String tv_date;
	//private TextView tv_type;
	private TextView tv_count;
	
	private AlertDialog.Builder adb;
	
	private String tv_sex1;
	private String tv_sex2;
//	private TextView tv_value1;
//	private TextView tv_value2;
	private String tv_desc1;
	private String tv_desc2;
	private String []detailStr = new String[2];
	
	private String []sexs;
	private short []timeLens = {30,180,360};
	private int timeLensCheckId = 0;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		//自定义title
		requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
		
		setContentView(R.layout.double_tow);
		
		getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.activity_title);
		
		initTitleBar();
		
		initView();
		initData();
		setListener();
		NaturalBiorhythmsApplication.addActivity(this);
	}
	
	private void initTitleBar() {
		Button btn_back = (Button)findViewById(R.id.button1_back);
		btn_back.setText(R.string.title_bar_btn1_back);
		TextView titleTxt =  (TextView)findViewById(R.id.textView1_title);
		titleTxt.setText(R.string.title_double_two_person);
		Button btn_other = (Button)findViewById(R.id.button2_other);
		btn_other.setText(R.string.title_bar_btn1_exit);
		btn_other.setBackgroundResource(R.anim.btn_style_exit);
		//btn_other.setEnabled(false);
		//btn_other.setVisibility(View.INVISIBLE);
		
		btn_back.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				finish();
			}
		});
		
		btn_other.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				NaturalBiorhythmsApplication.exitNaturalBiorhythmsApplication();
			}
		});
		
	}
	
	private void setListener() {
		
		listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				handler.sendMessage(handler.obtainMessage(DTPersonHandler.LIST_ITEM_CLICKED, DTPersonHandler.arg1_REFRESH_DETAIL, position));
			}
			
		});
		
		
		radioButton1_cycle.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				dayType_checkSwitch = DTPersonHandler.DAY_TYPE_1_CYCLE;
				handler.sendMessage(handler.obtainMessage(dayType_checkSwitch+tabCurrent_checkSwitch, DTPersonHandler.arg1_REFRESH_LISTVIEW, 0));
				setChecked(true, false, false, false, false, false);
			}
		});
		radioButton2_critical.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				dayType_checkSwitch = DTPersonHandler.DAY_TYPE_2_CRITICAL;
				handler.sendMessage(handler.obtainMessage(dayType_checkSwitch+tabCurrent_checkSwitch, DTPersonHandler.arg1_REFRESH_LISTVIEW, 0));
				setChecked(false,true, false, false, false, false);
			}
		});
		radioButton3_climax.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				dayType_checkSwitch = DTPersonHandler.DAY_TYPE_3_CLIMAX;
				handler.sendMessage(handler.obtainMessage(dayType_checkSwitch+tabCurrent_checkSwitch, DTPersonHandler.arg1_REFRESH_LISTVIEW, 0));
				setChecked(false, false,true, false, false, false);
			}
		});
		radioButton4_lowtide.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				dayType_checkSwitch = DTPersonHandler.DAY_TYPE_4_LOWTIDE;
				handler.sendMessage(handler.obtainMessage(dayType_checkSwitch+tabCurrent_checkSwitch, DTPersonHandler.arg1_REFRESH_LISTVIEW, 0));
				setChecked(false, false, false,true, false, false);
			}
		});
		radioButton5_climax_h.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				dayType_checkSwitch = DTPersonHandler.DAY_TYPE_5_CLIMAX_H;
				handler.sendMessage(handler.obtainMessage(dayType_checkSwitch+tabCurrent_checkSwitch, DTPersonHandler.arg1_REFRESH_LISTVIEW, 0));
				setChecked(false, false, false, false,true, false);
			}
		});
		radioButton6_lowtide_l.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				dayType_checkSwitch = DTPersonHandler.DAY_TYPE_6_LOWTIDE_L;
				handler.sendMessage(handler.obtainMessage(dayType_checkSwitch+tabCurrent_checkSwitch, DTPersonHandler.arg1_REFRESH_LISTVIEW, 0));
				setChecked(false, false, false, false, false,true);
			}
		});
		
		
		rg_timeLen.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			
			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				if(checkedId == R.id.radioButton1_timeLen_1month){
					timeLensCheckId = 0;
				}else if(checkedId == R.id.radioButton2_timeLen_6month){
					timeLensCheckId = 1;
				}else{
					timeLensCheckId = 2;
				}
				
				handler.sendMessage(handler.obtainMessage(dayType_checkSwitch+tabCurrent_checkSwitch, DTPersonHandler.arg1_REFRESH_LISTVIEW, 0));
			}
		});
		
		rg_types_tab.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			
			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {

				
				if(checkedId == R.id.radioButton1_type_physical){
					tabCurrent_checkSwitch = DTPersonHandler.TAB_1_PHYSICAL;
				}else if(checkedId == R.id.radioButton2_type_emotional){
					tabCurrent_checkSwitch = DTPersonHandler.TAB_2_EMOTIONAL;
				}else if(checkedId == R.id.radioButton3_type_intellictual){
					tabCurrent_checkSwitch = DTPersonHandler.TAB_3_INTELLICTUAL;
				}else if(checkedId == R.id.radioButton4_type_intuitive){
					tabCurrent_checkSwitch = DTPersonHandler.TAB_4_INTUITIVE;
				}
			
				handler.sendMessage(handler.obtainMessage(dayType_checkSwitch+tabCurrent_checkSwitch, DTPersonHandler.arg1_REFRESH_LISTVIEW, 0));
			}
		});
	}
	private void initView() {
		sexs = new String[]{getString(R.string.sex1_text),getString(R.string.sex2_text)};
		bsspref = BirthdaySettingsSharePref.getInstance(this);
        
		listView = (ListView)findViewById(R.id.listview_towperson);
		tv_count = (TextView)findViewById(R.id.textView3_DaysCount);
		/*tv_date = (TextView)view.findViewById(R.id.textView1_Date);
		//tv_type = (TextView)findViewById(R.id.textView2_Type);
		
		
		//
		tv_sex1 = (TextView)view.findViewById(R.id.textView4_sex);
		tv_sex2 = (TextView)view.findViewById(R.id.textView8_sex);
		
		tv_value1 = (TextView)view.findViewById(R.id.textView5_value);
		tv_value2 = (TextView)view.findViewById(R.id.textView9_value);
		
		tv_desc1 = (TextView)view.findViewById(R.id.textView6_desc);
		tv_desc2 = (TextView)view.findViewById(R.id.textView10_desc);*/
		
		
		radioButton1_cycle = (RadioButton)findViewById(R.id.radioButton1_cycle);
		radioButton2_critical = (RadioButton)findViewById(R.id.radioButton2_critical);
		radioButton3_climax = (RadioButton)findViewById(R.id.radioButton3_climax);
		radioButton4_lowtide = (RadioButton)findViewById(R.id.radioButton4_lowtide);
		radioButton5_climax_h = (RadioButton)findViewById(R.id.radioButton5_climax_h);
		radioButton6_lowtide_l = (RadioButton)findViewById(R.id.radioButton6_lowtide_l);
		
		rg_timeLen = (RadioGroup)findViewById(R.id.layout_radiogroup_timeLen);
		rg_types_tab = (RadioGroup)findViewById(R.id.layout_radiogroup_type);
		
		initAlertDialog();
	}
	
	private void initData() {
		birthday1 = bsspref.getBirthday((byte)0);
		sex1 = bsspref.getSex((byte)0);
		tv_sex1 = sexs[sex1];
		nba1 = new NaturalBiorhythmsAlgorithm(birthday1);
		
		birthday2 = bsspref.getBirthday((byte)1);
		sex2 = bsspref.getSex((byte)1);
		tv_sex2 = sexs[sex2];
		nba2 = new NaturalBiorhythmsAlgorithm(birthday2);
		
		//adpter =  new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, data);
		adpter = new NaturalBirthdayAdapter(this, data);
		listView.setAdapter(adpter);
		
		
		handler = new DTPersonHandler();
		
	}
	
	
	private void setChecked(boolean check1,boolean check2,boolean check3,boolean check4,boolean check5,boolean check6){
		radioButton1_cycle.setChecked(check1);
		radioButton2_critical.setChecked(check2);
		radioButton3_climax.setChecked(check3);
		radioButton4_lowtide.setChecked(check4);
		radioButton5_climax_h.setChecked(check5);
		radioButton6_lowtide_l.setChecked(check6);
		
	}
	
	class DTPersonHandler extends Handler{
		
		private static final int DAY_TYPE_1_CYCLE = 1;
		private static final int DAY_TYPE_2_CRITICAL = 2;
		private static final int DAY_TYPE_3_CLIMAX = 4;
		private static final int DAY_TYPE_4_LOWTIDE = 8;
		private static final int DAY_TYPE_5_CLIMAX_H = 16;
		private static final int DAY_TYPE_6_LOWTIDE_L = 32;
		
		private static final int TAB_1_PHYSICAL = 64;
		private static final int TAB_2_EMOTIONAL = 128;
		private static final int TAB_3_INTELLICTUAL = 256;
		private static final int TAB_4_INTUITIVE = 512;
		
		private static final int arg1_REFRESH_LISTVIEW = 1;//刷新列表
		
		private static final int LIST_ITEM_CLICKED = 999;
		private static final int arg1_REFRESH_DETAIL = 2;//刷新详细
		@Override
		public void handleMessage(Message msg) {
			long fromeTime = 0;
			long toTime = 0;
			try {
				fromeTime = NaturalBiorhythmsAlgorithm.SDF_DATE_yyyy_MM_dd.parse(NaturalBiorhythmsAlgorithm.SDF_DATE_yyyy_MM_dd.format(new Date())).getTime();
				toTime = fromeTime+NaturalBiorhythmsAlgorithm.ONE_DAY_MILLISECONDS*timeLens[timeLensCheckId];
			} catch (ParseException e) {
				e.printStackTrace();
			}
			
			List<Long> data1 = null;
			List<Long> data2 = null;
			
			String tabstr = getString(R.string.physical);
			String typestr = getString(R.string.DayInCycle_Cycle_RB);
			
			
			switch(msg.what){
			case DAY_TYPE_1_CYCLE+TAB_1_PHYSICAL:
				data1 = nba1.getDaysIn_CycleDay_Physical(fromeTime, toTime);
				data2 = nba2.getDaysIn_CycleDay_Physical(fromeTime, toTime);
				
				tabstr = getString(R.string.physical);
				typestr = getString(R.string.DayInCycle_Cycle_RB);
				break;
			case DAY_TYPE_1_CYCLE+TAB_2_EMOTIONAL:
				data1 = nba1.getDaysIn_CycleDay_Emotional(fromeTime, toTime);
				data2 = nba2.getDaysIn_CycleDay_Emotional(fromeTime, toTime);
				
				tabstr = getString(R.string.emotional);
				typestr = getString(R.string.DayInCycle_Cycle_RB);
				break;
			case DAY_TYPE_1_CYCLE+TAB_3_INTELLICTUAL:
				data1 = nba1.getDaysIn_CycleDay_Intellictual(fromeTime, toTime);
				data2 = nba2.getDaysIn_CycleDay_Intellictual(fromeTime, toTime);
				
				tabstr = getString(R.string.intellictual);
				typestr = getString(R.string.DayInCycle_Cycle_RB);
				break;
			case DAY_TYPE_1_CYCLE+TAB_4_INTUITIVE:
				data1 = nba1.getDaysIn_CycleDay_Intuitive(fromeTime, toTime);
				data2 = nba2.getDaysIn_CycleDay_Intuitive(fromeTime, toTime);
				
				tabstr = getString(R.string.intuitive);
				typestr = getString(R.string.DayInCycle_Cycle_RB);
				break;
				
			//	
			case DAY_TYPE_2_CRITICAL+TAB_1_PHYSICAL:
				data1 = nba1.getDaysIn_CriticalDay_Physical(fromeTime, toTime);
				data2 = nba2.getDaysIn_CriticalDay_Physical(fromeTime, toTime);
				
				tabstr = getString(R.string.physical);
				typestr = getString(R.string.DayInCycle_Critical_RB);
				break;
			case DAY_TYPE_2_CRITICAL+TAB_2_EMOTIONAL:
				data1 = nba1.getDaysIn_CriticalDay_Emotional(fromeTime, toTime);
				data2 = nba2.getDaysIn_CriticalDay_Emotional(fromeTime, toTime);
				
				tabstr = getString(R.string.emotional);
				typestr = getString(R.string.DayInCycle_Critical_RB);
				break;
			case DAY_TYPE_2_CRITICAL+TAB_3_INTELLICTUAL:
				data1 = nba1.getDaysIn_CriticalDay_Intellictual(fromeTime, toTime);
				data2 = nba2.getDaysIn_CriticalDay_Intellictual(fromeTime, toTime);
				
				tabstr = getString(R.string.intellictual);
				typestr = getString(R.string.DayInCycle_Critical_RB);
				break;
			case DAY_TYPE_2_CRITICAL+TAB_4_INTUITIVE:
				data1 = nba1.getDaysIn_CriticalDay_Intuitive(fromeTime, toTime);
				data2 = nba2.getDaysIn_CriticalDay_Intuitive(fromeTime, toTime);
				
				tabstr = getString(R.string.intuitive);
				typestr = getString(R.string.DayInCycle_Critical_RB);
				break;
				
			//
			case DAY_TYPE_3_CLIMAX+TAB_1_PHYSICAL:
				data1 = nba1.getDaysIn_Hightide_Physical(fromeTime, toTime);
				data2 = nba2.getDaysIn_Hightide_Physical(fromeTime, toTime);
				
				tabstr = getString(R.string.physical);
				typestr = getString(R.string.DayInCycle_Climax_RB);
				break;
			case DAY_TYPE_3_CLIMAX+TAB_2_EMOTIONAL:
				data1 = nba1.getDaysIn_Hightide_Emotional(fromeTime, toTime);
				data2 = nba2.getDaysIn_Hightide_Emotional(fromeTime, toTime);
				
				tabstr = getString(R.string.emotional);
				typestr = getString(R.string.DayInCycle_Climax_RB);
				break;
			case DAY_TYPE_3_CLIMAX+TAB_3_INTELLICTUAL:
				data1 = nba1.getDaysIn_Hightide_Intellictual(fromeTime, toTime);
				data2 = nba2.getDaysIn_Hightide_Intellictual(fromeTime, toTime);
				
				tabstr = getString(R.string.intellictual);
				typestr = getString(R.string.DayInCycle_Climax_RB);
				break;
			case DAY_TYPE_3_CLIMAX+TAB_4_INTUITIVE:
				data1 = nba1.getDaysIn_Hightide_Intuitive(fromeTime, toTime);
				data2 = nba2.getDaysIn_Hightide_Intuitive(fromeTime, toTime);
				
				tabstr = getString(R.string.intuitive);
				typestr = getString(R.string.DayInCycle_Climax_RB);
				break;
				
			case DAY_TYPE_4_LOWTIDE+TAB_1_PHYSICAL:
				data1 = nba1.getDaysIn_Lowtide_Physical(fromeTime, toTime);
				data2 = nba2.getDaysIn_Lowtide_Physical(fromeTime, toTime);
				
				tabstr = getString(R.string.physical);
				typestr = getString(R.string.DayInCycle_Lowtide_RB);
				break;
			case DAY_TYPE_4_LOWTIDE+TAB_2_EMOTIONAL:
				data1 = nba1.getDaysIn_Lowtide_Emotional(fromeTime, toTime);
				data2 = nba2.getDaysIn_Lowtide_Emotional(fromeTime, toTime);
				
				tabstr = getString(R.string.emotional);
				typestr = getString(R.string.DayInCycle_Lowtide_RB);
				break;
			case DAY_TYPE_4_LOWTIDE+TAB_3_INTELLICTUAL:
				data1 = nba1.getDaysIn_Lowtide_Intellictual(fromeTime, toTime);
				data2 = nba2.getDaysIn_Lowtide_Intellictual(fromeTime, toTime);
				
				tabstr = getString(R.string.intellictual);
				typestr = getString(R.string.DayInCycle_Lowtide_RB);
				break;
			case DAY_TYPE_4_LOWTIDE+TAB_4_INTUITIVE:
				data1 = nba1.getDaysIn_Lowtide_Intuitive(fromeTime, toTime);
				data2 = nba2.getDaysIn_Lowtide_Intuitive(fromeTime, toTime);
				
				tabstr = getString(R.string.intuitive);
				typestr = getString(R.string.DayInCycle_Lowtide_RB);
				break;
				
			case DAY_TYPE_5_CLIMAX_H+TAB_1_PHYSICAL:
				data1 = nba1.getDaysIn_Highest_Physical(fromeTime, toTime);
				data2 = nba2.getDaysIn_Highest_Physical(fromeTime, toTime);
				
				tabstr = getString(R.string.physical);
				typestr = getString(R.string.DayInCycle_Climax_H_RB);
				break;
			case DAY_TYPE_5_CLIMAX_H+TAB_2_EMOTIONAL:
				data1 = nba1.getDaysIn_Highest_Emotional(fromeTime, toTime);
				data2 = nba2.getDaysIn_Highest_Emotional(fromeTime, toTime);
				
				tabstr = getString(R.string.emotional);
				typestr = getString(R.string.DayInCycle_Climax_H_RB);
				break;
			case DAY_TYPE_5_CLIMAX_H+TAB_3_INTELLICTUAL:
				data1 = nba1.getDaysIn_Highest_Intellictual(fromeTime, toTime);
				data2 = nba2.getDaysIn_Highest_Intellictual(fromeTime, toTime);
				
				tabstr = getString(R.string.intellictual);
				typestr = getString(R.string.DayInCycle_Climax_H_RB);
				break;
			case DAY_TYPE_5_CLIMAX_H+TAB_4_INTUITIVE:
				data1 = nba1.getDaysIn_Highest_Intuitive(fromeTime, toTime);
				data2 = nba2.getDaysIn_Highest_Intuitive(fromeTime, toTime);
				
				tabstr = getString(R.string.intuitive);
				typestr = getString(R.string.DayInCycle_Climax_H_RB);
				break;
				
			case DAY_TYPE_6_LOWTIDE_L+TAB_1_PHYSICAL:
				data1 = nba1.getDaysIn_Lowest_Physical(fromeTime, toTime);
				data2 = nba2.getDaysIn_Lowest_Physical(fromeTime, toTime);
				
				tabstr = getString(R.string.physical);
				typestr = getString(R.string.DayInCycle_Lowtide_L_RB);
				break;
			case DAY_TYPE_6_LOWTIDE_L+TAB_2_EMOTIONAL:
				data1 = nba1.getDaysIn_Lowest_Emotional(fromeTime, toTime);
				data2 = nba2.getDaysIn_Lowest_Emotional(fromeTime, toTime);
				
				tabstr = getString(R.string.emotional);
				typestr = getString(R.string.DayInCycle_Lowtide_L_RB);
				break;
			case DAY_TYPE_6_LOWTIDE_L+TAB_3_INTELLICTUAL:
				data1 = nba1.getDaysIn_Lowest_Intellictual(fromeTime, toTime);
				data2 = nba2.getDaysIn_Lowest_Intellictual(fromeTime, toTime);
				
				tabstr = getString(R.string.intellictual);
				typestr = getString(R.string.DayInCycle_Lowtide_L_RB);
				break;
			case DAY_TYPE_6_LOWTIDE_L+TAB_4_INTUITIVE:
				data1 = nba1.getDaysIn_Lowest_Intuitive(fromeTime, toTime);
				data2 = nba2.getDaysIn_Lowest_Intuitive(fromeTime, toTime);
				
				tabstr = getString(R.string.intuitive);
				typestr = getString(R.string.DayInCycle_Lowtide_L_RB);
				break;
			case LIST_ITEM_CLICKED:
				
				break;
				
			}
			
			switch(msg.arg1){
			case arg1_REFRESH_LISTVIEW:
				if(data1 == null || data2 == null ){
					return;
				}
				
				//交集
				data1.retainAll(data2);
				
				adpter.clear();
				for(Long l:data1){
					Map<String,Object> object = new HashMap<String, Object>();
					object.put(NaturalBirthdayAdapter.key_title, NaturalBiorhythmsAlgorithm.SDF_DATE_yyyy_MM_dd.format(new Date(l)));
					object.put(NaturalBirthdayAdapter.key_content, "");
					
					adpter.add(object);
				}
				adpter.notifyDataSetChanged();
				listView.invalidate();
				tv_count.setText(String.format(getString(R.string.days_count), adpter.getCount(),tabstr + typestr ));
				updateUiText(0);
				break;
			case arg1_REFRESH_DETAIL:
				updateUiText(msg.arg2);
				detailStr[0] = getString(R.string.birthday1_you_text)+"\t"+tv_sex1+"\t"+tv_desc1;
				detailStr[1] = getString(R.string.birthday2_ta_text)+"\t"+tv_sex2+"\t"+tv_desc2;
				adb.setTitle(tv_date);
				adb.show();
				break;
			}
			
		}
		
		private void updateUiText(int pos){
			if(adpter.getCount()<=0){
				return;
			}
			//String dateStr = adpter.getItem(pos);
			Map<String,Object> object = (Map<String,Object>)adpter.getItem(pos);
			String dateStr = object.get(NaturalBirthdayAdapter.key_title).toString();
			long dateLong = 0;
			try {
				dateLong = NaturalBiorhythmsAlgorithm.SDF_DATE_yyyy_MM_dd.parse(dateStr).getTime();
			} catch (ParseException e) {
				e.printStackTrace();
			}
			
			long livedDays1 = nba1.getLivedDays(dateLong);
			long livedDays2 = nba2.getLivedDays(dateLong);
			
			tv_date = dateStr;
			byte d1 = 0;
			byte d2 = 0;
			switch(tabCurrent_checkSwitch){
			case TAB_1_PHYSICAL:
				//tv_type.setText(getString(R.string.physical));
				d1 = nba1.getDayInCyclePhysical(livedDays1);
				d2 = nba1.getDayInCyclePhysical(livedDays2);
				
				break;
			case TAB_2_EMOTIONAL:
				//tv_type.setText(getString(R.string.emotional));
				d1 = nba1.getDayInCycleEmotional(livedDays1);
				d2 = nba1.getDayInCycleEmotional(livedDays2);
				
				break;
			case TAB_3_INTELLICTUAL:
				//tv_type.setText(getString(R.string.intellictual));
				d1 = nba1.getDayInCycleIntellictual(livedDays1);
				d2 = nba1.getDayInCycleIntellictual(livedDays2);
				
				break;
			case TAB_4_INTUITIVE:
				//tv_type.setText(getString(R.string.intuitive));
				d1 = nba1.getDayInCycleIntuitive(livedDays1);
				d2 = nba1.getDayInCycleIntuitive(livedDays2);
				
				break;
			}
			
			switch(dayType_checkSwitch){
			case DAY_TYPE_1_CYCLE:
				tv_desc1 = getString(R.string.DayInCycle_Cycle_text);
				tv_desc2 = getString(R.string.DayInCycle_Cycle_text);
				break;
			case DAY_TYPE_2_CRITICAL:
				tv_desc1 = getString(R.string.DayInCycle_Critical_text);
				tv_desc2 = getString(R.string.DayInCycle_Critical_text);
				break;
			case DAY_TYPE_3_CLIMAX:
				tv_desc1 = String.format(getString(R.string.DayInCycle_Climax_text), d1);
				tv_desc2 = (String.format(getString(R.string.DayInCycle_Climax_text), d2));
				break;
			case DAY_TYPE_4_LOWTIDE:
				tv_desc1 = String.format(getString(R.string.DayInCycle_Lowtide_text), d1);
				tv_desc2 = String.format(getString(R.string.DayInCycle_Lowtide_text), d2);
				break;
			case DAY_TYPE_5_CLIMAX_H:
				tv_desc1 = getString(R.string.DayInCycle_Climax_H_text);
				tv_desc2 = getString(R.string.DayInCycle_Climax_H_text);
				break;
			case DAY_TYPE_6_LOWTIDE_L:
				tv_desc1 = getString(R.string.DayInCycle_Lowtide_L_text);
				tv_desc2 = getString(R.string.DayInCycle_Lowtide_L_text);
				break;
			}
		}
	}
	
	
	private void initAlertDialog(){
		adb = new AlertDialog.Builder(DoubleTowPersonActivity.this);
		adb.setTitle(tv_date);
		adb.setItems(detailStr, null);
		adb.setPositiveButton(R.string.positivebutton_text, null);
		adb.setCancelable(true);
	}
}
